package com.javaex.book.dao.impl;

import java.util.List;

import com.javaex.book.dao.OrderItemDao;
import com.javaex.book.pojo.OrderItem;

public class OrderItemDaoImpl extends BaseDao implements OrderItemDao {

	@Override
	public Integer saveOrderItem(OrderItem orderItem) {
		String sql = "insert into orderItems(name, count, price, orderId, totalPrice) values(?, ? ,? ,?, ?)";
		return execute(sql, orderItem);
	}
	
	@Override
	public Integer countOrderItems(String orderId) {
		if (orderId == null) {
			return null;
		}
		String sql = "select count(*) from orderItems where orderId = ?";
		return count(sql, new Object[] { orderId });
	}

	@Override
	public List<OrderItem> queryOrderItemsByOrderId(String orderId, Integer start, Integer pageSize) {
		String sql = "select id, name, count, price, orderId, totalPrice from orderItems where orderId = ? order by id limit ?, ?";
		return findMany(sql, OrderItem.class, new Object[] { orderId, start, pageSize });
	}

	@Override
	public Integer deleteOrderItems(String orderId) {
		String sql = "delete from orderItems where orderId = ?";
		return execute(sql, new Object[] { orderId });
	}
}
